package com.semanticweb.webapp.model.rbac;

import java.io.Serializable;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import org.apache.commons.lang3.builder.EqualsBuilder;

/**
 * Abstract entity object with id that is automatically generated.
 * 
 * @author Vedran Cuca 19/2011
 */
@MappedSuperclass
public class AbstractPersistedEntity implements Serializable {

	private static final long serialVersionUID = 6437568439662585049L;

	public static final String ID = "id";

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	protected Long id;

	/**
	 * Default constructor.
	 */
	public AbstractPersistedEntity() {
		super();
	}

	public Long getId() {
		return id;
	}

	public void setId(final Long id) {
		this.id = id;
	}

	@Override
	public String toString() {
		return "AbstractPersistedEntity [id=" + id + "]";
	}

	public boolean equals(final Object object) {
		if (!(object instanceof AbstractPersistedEntity)) {
			return false;
		}
		final AbstractPersistedEntity other = (AbstractPersistedEntity) object;
		return new EqualsBuilder().append(this.id, other.id).isEquals();
	}

}
